﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EquipSecs300
{

    public class Prm
    {
        [Category("a.Train参数"), DisplayName("01.检测参数"), Description("")]
        [TypeConverter(typeof(ExpandableObjectConverter))]
        public InspectionInsp InspParam { get; set; } = new InspectionInsp();

        [Category("a.Train参数"), DisplayName("02.光源参数"), Description("")]
        [TypeConverter(typeof(ExpandableObjectConverter))]
        public Light Light { get; set; } = new Light();
    }

    public class InspectionInsp
    {

        [DisplayName("量测参数: 硬件选择"), Description("硬件选择"), Browsable(true)]
        //[DisplayName("检测参数: 硬件选择"), Description("硬件选择"), Browsable(true)]
        [TypeConverter(typeof(ExpandableObjectConverter))]
        public PRM_LenGP_Sel GPSel_Insp { get; set; } = new PRM_LenGP_Sel();

        PRM_LenGP_Sel _GPSel_ALG = new PRM_LenGP_Sel();
        [DisplayName("对位参数: 硬件选择"), Description("硬件选择"), Browsable(true)]
        [TypeConverter(typeof(ExpandableObjectConverter))]
        public PRM_LenGP_Sel GPSel_ALG { get; set; } = new PRM_LenGP_Sel();

        [DisplayName("量测参数"), Description(""), Browsable(true)]
        [TypeConverter(typeof(ExpandableObjectConverter))]
        public PRM_ShiftMeasurParam ShiftMeasure { get; set; } = new PRM_ShiftMeasurParam();

        [DisplayName("机台参数: 大吸力真空开启"), Description(""), Browsable(true)]
        public bool LargeFlowVacEnable { get; set; } = false;
    }

    public class Light
    {
        [Category("光源参数"), DisplayName("★镜组A: 光源模式选择"), Description("光源模式选择：红外光; 可见光"), ReadOnly(false)]
        public string InspALightMode { get; set; } = "红外光";

        [Category("光源参数"), DisplayName("★镜组B: 光源模式选择"), Description("光源模式选择：红外光; 可见光"), ReadOnly(false)]
        public string InspBLightMode { get; set; } = "可见光";

        [Category("光源参数"), DisplayName("01.对位相机光源亮度设定(Wafer边沿)"), Description("对位相机同轴光源亮度(Wafer边沿)")]
        public int Align_Circle { get; set; } = 10;

        [Category("光源参数"), DisplayName("02.对位相机光源亮度设定(Mark)"), Description("对位相机同轴光源亮度(Mark)")]
        public int Align_Mark { get; set; } = 10;

    }

    public class PRM_LenGP_Sel
    {
        [DisplayName("镜组选择"), Description("镜组选择：镜组A; 镜组B;"), Browsable(true)]
        public string GP { get; set; } = "镜组A";

        [DisplayName("相机选择"), Description("相机选择：CamA; CamB"), Browsable(true)]
        public string Cam { get; set; } = "CamA";

        [DisplayName("镜头选择"), Description("镜头选择：2X; 3X; 5X; 10X"), Browsable(true)]
        public string Len { get; set; } = "5X";

        public override string ToString()
        {
            return "...";
        }
    }

    public class PRM_ShiftMeasurParam
    {

        [DisplayName("★量测功能开启"), Description("量测功能:true开启，false关闭"), Browsable(true)]
        public bool Enable { get; set; } = true;

        private double _InspSpeed = 25;
        [DisplayName("检测速度"), Description("检测运转速度(mm/s)"), ReadOnly(false), Browsable(false)]
        public double InspSpeed
        {
            get { return _InspSpeed; }
            set
            {
                _InspSpeed = value;
                if (_InspSpeed > 150)
                {
                    _InspSpeed = 150;
                }
                if (_InspSpeed < 1)
                {
                    _InspSpeed = 1;
                }
            }
        }

        [DisplayName("抽检功能：Port抽检开启"), Description("隔层抽检功能:true开启，false关闭"), Browsable(true)]
        public bool SamplingCheckEnable { get; set; } = false;

        [DisplayName("抽检功能：Port抽检层数设定"), Description("true:检查；false:不检查"), Browsable(true)]
        public bool[] PortSels { get; set; } = new bool[13] { true, true, true, true, true, true, true, true, true, true, true, true, true };

        public int[] PortSelsInt { get; set; } = new int[13] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };

        public List<int> PortSelsIntList { get; set; } = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };

        [DisplayName("自动对焦: 取图重试次数"), Description("单位(次)"), Browsable(true)]
        public int GrapRetryCount { get; set; } = 2;


        [DisplayName("量测程序集合"), Description("量测程序集合"), Browsable(false)]
        public Dictionary<int, PRM_ShiftMeasure> Progs { get; set; } = new Dictionary<int, PRM_ShiftMeasure>();

        public Point Point { get; set; } = new Point() { X = 123, Y = 456 };

        public PRM_ShiftMeasurParam()
        {
            for (int i = 0; i < 4; i++)
            {
                Progs.Add(i, new PRM_ShiftMeasure());
            }
        }
    }

    public class PRM_ShiftMeasure
    {

        [Browsable(false)]
        public int RegionID { get; set; } = 0;

        [Category("0.基本参数"), DisplayName("1.检测区域是否启用"), Description("检测区域是否启用")]
        public bool RegionEnable { get; set; } = true;

        [Category("0.基本参数"), DisplayName("2.镜头倍率"), Description("检测镜头信息：2X; 3X; 5X; 10X"), Browsable(false)]
        public string LenInfo { get; set; } = "10X";

        [Category("1.量测方法"), DisplayName("1.方法集合"), Description("方法集合"), ReadOnly(false)]
        public Dictionary<int, PRM_MeasureMethod> Dic_Methods { get; set; } = new Dictionary<int, PRM_MeasureMethod>();
        public override string ToString()
        {
            return "...";
        }
        public PRM_ShiftMeasure()
        {
            Dic_Methods = new Dictionary<int, PRM_MeasureMethod>();
            for (int i = 0; i < 3; i++)
            {
                Dic_Methods.Add(i, new PRM_MeasureMethod());
            }
        }
    }
    public class PRM_MeasurePointPar
    {
        [DisplayName("1.定位点坐标"), Description("定位点位XYZ坐标"), Browsable(false)]
        public InspPoint LocatePoint { get; set; } = new InspPoint();

        [DisplayName("2.检测光源亮度"), Description("光源亮度"), Browsable(false)]
        public int LightValue { get; set; } = 10;

        [DisplayName("3.Shape文件名标签"), Description("Shape文件名标签"), Browsable(false)]
        public string ShapeFileTag { get; set; } = "00";

        public override string ToString()
        {
            return string.Format("[{0}]-坐标X:{1:F3} Y:{2:F3} Z:{3:F3}", ShapeFileTag, LocatePoint.X, LocatePoint.Y, LocatePoint.Z);
        }
    }

    [Serializable]
    public class PRM_MeasureMethod
    {
        [Browsable(false)]
        public int RegionID { get; set; } = 0;

        [DisplayName("1.方法名标签"), Description("方法名标签"), Browsable(false)]
        public string MethodTag { get; set; } = "Distance";

        [DisplayName("2.计算点集合"), Description("基准，单位:mm"), ReadOnly(false)]
        public Dictionary<int, string> Dic_PointShapeFileTag { get; set; } = new Dictionary<int, string>();

        [DisplayName("3.参考基准"), Description("基准，单位:mm"), ReadOnly(false)]
        public PRM_MeasureReferenceData BaseData { get; set; } = new PRM_MeasureReferenceData();

        public override string ToString()
        {
            return "...";
        }
        public PRM_MeasureMethod()
        {
            Dic_PointShapeFileTag = new Dictionary<int, string>();
            {
                for (int i = 0; i < 3; i++)
                {
                    Dic_PointShapeFileTag.Add(i, "str" + i);
                }
            }
        }
    }

    [Serializable]
    public class PRM_MeasureReferenceData
    {
        [DisplayName("1.基准值"), Description("基准值，单位:mm"), ReadOnly(false)]
        public InspPoint BenchMark { get; set; } = new InspPoint();

        [DisplayName("2.卡控范围（+-）"), Description("卡控范围，单位:mm"), ReadOnly(false)]
        public InspPoint LimitRange { get; set; } = new InspPoint();

        public override string ToString()
        {
            return "...";
        }
    }

    public class InspPoint
    {
        public double X
        {
            get; set;
        }
        public double Y
        {
            get; set;
        }
        public double Z
        {
            get; set;
        }
        public double R
        {
            get; set;
        }

        public InspPoint()
        {
            this.X = 0;
            this.Y = 1.1;
            this.Z = 2.1;
            this.R = 3.1;
        }
    }
}